package org.smartjava.concurrent.juc;

import org.smartjava.util.PrintUtil;
import org.smartjava.util.ThreadUtil;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableExample {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Integer one = 1;
        Integer two = 2;
        Callable<Integer> callable = () -> {
            PrintUtil.print("Do a lot of things");
            ThreadUtil.sleep(1);
            PrintUtil.print("A few moments later");
            return one + two;
        };
        FutureTask futureTask = new FutureTask(callable);
        new Thread(futureTask).start();
        PrintUtil.print("开始计算");
        PrintUtil.print(futureTask.get());

    }
}
